<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <title>忘记密码 小熊猫金服</title>
    <link href="{{'/css/style.css'}}" rel="stylesheet" type="text/css" />
    <link href="{{'/css/login.css'}}" rel="stylesheet" type="text/css" />
    <script src="{{'/js/jquery-1.7.1.min.js'}}" type="text/javascript"></script>
    <script src="{{'/js/js.js'}}" type="text/javascript"></script>
</head>
<body>
<!--header start-->
<div class="header_reg">
    <div class="logo"><a href="/"><img src="{{asset('images/logo_reg.png')}}"/></a></div>
</div>
<!--header end-->


<!--main start-->
<form>
    <div class="reg_box_w">
        <div class="reg_box">

            <div class="tit">忘记密码</div>
            <div class="reg_form">

                <div class="i2_w"><input class="input" id="mobile" name="mobile" type="text"   placeholder="必填项：请输入手机号码" onkeyup='this.value=this.value.replace(/\D/gi,"")'/>
                </div>
                <div class="col-sm-3  disnone " id="mobileError" style="color:red;text-align: center;font-size: 18px;"></div>
                <div class="line">
                    <div class="btn_qr"  type="button">获取验证码</div>
                    <div class="i3_w"><input class="input_3" id="validateCode" name="validateCode" type=""  placeholder="请输入手机验证码" />
                    </div>

                    <div class="clear"></div>
                </div>
                <div class="col-sm-3  disnone " id="validateCodeError" style="color:red;text-align: center;font-size: 18px;"></div>
                <div class="i2_w"><input class="input" id="password" name="password" type="password"    placeholder="请设置新密码" />
                </div>
                <div class="col-sm-3  disnone " id="passwordError" style="color:red;text-align: center;font-size: 18px;"></div>
                <div class="i2_w"><input class="input" id="confirmPassword" name="confirmPassword" type="password"    placeholder="请输入确认密码" />
                </div>
                <div class="col-sm-3  disnone " id="confirmPasswordError" style="color:red;text-align: center;font-size: 18px;"></div>

                <div class="error-message  disnone "  style="color:red;text-align: center;font-size: 18px;"></div>
                <div class="btn_w"><button  class="btn  registerbut" type="button">提交</button>
                </div>

            </div>
        </div>
    </div>
</form>
<!--main end-->

<!--footer start-->
<!--footer end-->
<script type="text/javascript" language="JavaScript">

    $(function(){
        //初始化
        $(".reg_box_w input").val('');

        //获取验证码
        $(".btn_qr").on('click' , function(){
            $.ajax({
                type: "POST",
                url: "{{url('user/validatecode')}}",
                data: {'mobile':$("#mobile").val(), '_token': '{{csrf_token()}}' }
            }).always(function(data){
                alert(data.content);
            });
        });

        $(".registerbut").click(function() {
            var mobile = $("#mobile").val();
            var password = $("#password").val();
            var confirmPassword = $("#confirmPassword").val();
            var validateCode = $("#validateCode").val();
            //验证手机号
            if (mobile == "") {
                $("#mobileError").text('*手机号不能为空').show();
                return true;
            } else {
                $("#mobileError").hide();
            }

            if (mobile.length < 11) {
                $("#mobileError").text('*请输入正确的手机号码').show();
                return true;
            }

            var reg = /^1[3|4|5|6|7|8|9]\d{9}$/g;
            if (reg.test(mobile) == true) {
                $("#mobileError").hide();
            } else {
                $("#mobileError").text('*请输入正确的手机号码').show();
                return true;
            }

            //验证验证码
            if(validateCode == ""){
                $("#validateCodeError").text('*验证码不能为空').show();
                return true;
            }else {
                $("#validateCodeError").hide();
            }
            if(validateCode.length != 4){
                $("#validateCodeError").text('*请输入正确的验证码').show();
                return true;
            }else {
                $("#validateCodeError").hide();
            }
            //验证密码
            if(password == ""){
                $("#passwordError").text('*新密码不能为空').show();
                return true;
            }else{
                $("#passwordError").hide();
            }

            var regex = /^\w{6,15}$/;
            if (regex.test(password) == true) {
                $("#passwordError").hide();
            } else {
                $("#passwordError").text('*请输入6-15位密码，不允许有特殊符号').show();
                return true;
            }
            //确认密码
            if(confirmPassword == ""){
                $("#confirmPasswordError").text('*确认密码不能为空').show();
                return true;
            }else{
                $("#confirmPasswordError").hide();
            }

            if( password != confirmPassword){
                $(".error-message").text('*密码、确认密码不一致，请重新输入').show();
                return true
            }else{
                $(".error-message").hide();
            }

            var url = '/user/forget-password';
            var sflData = {};
            sflData.mobile = mobile;
            sflData.validateCode = validateCode;
            sflData.password = password;
            sflData._token = '{{csrf_token()}}';
            $.ajax({
                type: 'POST',
                url:  url,
                data: sflData,
                dataType: 'json',
                success: function(data) {
                    if (data.code == 200) {
                        window.location.href = '/user/login';
                        return true;
                    }
                    if (data.code == 40001 ) {
                        $(".error-message").text("用户不存在，无法设置新密码").show();
                        return true;
                    }
                    if (data.code == 40102 ) {
                        $(".error-message").text("验证码错误").show();
                        return true;
                    }
                    if (data.code == 50001 ) {
                        $(".error-message").text("更新数据失败，如有问题请联系管理员").show();
                        return true;
                    }
                }
            })
        })
    });


</script>

</body>
</html>